package fr.ul.ade.secunde.ui.phone;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import fr.ul.ade.R;
import fr.ul.ade.secunde.ui.HelpActionListener;
import fr.ul.ade.secunde.ui.LessonActionListener;
import fr.ul.ade.secunde.ui.ScheduleActionListener;
import fr.ul.ade.secunde.util.Bundles;

/**
 * Activité responsable de l'afficahge de la liste des cours d'un emploi du
 * temps donné.
 * 
 * @author Michaël Schnell
 * @since Jul 2, 2013
 * 
 * @version 1.4
 */
public class LessonList
		extends SherlockFragmentActivity
		implements ScheduleActionListener, HelpActionListener,
		LessonActionListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_lesson_list);
		// Show the Up button in the action bar.
		this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		this.getSupportMenuInflater().inflate(R.menu.lesson_list, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
			
		case R.id.action_sync_schedule:
			Intent updateIntent = new Intent(this.getResources()
					.getString(R.string.intent_action_update_schedule));
			updateIntent.putExtra(Bundles.SCHEDULE_ID, this.getIntent()
					.getLongExtra(Bundles.SCHEDULE_ID, 0));
			this.startService(updateIntent);
			return true;

		case R.id.action_edit:
			this.showEditForm(this.getIntent()
					.getLongExtra(Bundles.SCHEDULE_ID, 0));
			return true;

		case R.id.action_help:

		default:
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void showLessonDetails(long scheduleId, long lessonId) {
		this.startActivity(new Intent(this, LessonDetails.class)
				.putExtra(Bundles.LESSON_DETAILS_SCHEDULE_ID, scheduleId)
				.putExtra(Bundles.LESSON_DETAILS_ID, lessonId));
	}

	@Override
	public void showHelp() {
		// TODO Auto-generated method stub
	}

	@Override
	public void showEditForm(long scheduleId) {
		this.startActivity(new Intent(this, EditSchedule.class)
				.putExtra(Bundles.SCHEDULE_ID, scheduleId));
	}

	/* ------------------------------------------------- */

	@Override
	public void showScheduleDetails(long scheduleId, String scheduleName) {
		/* Action impossible. */
	}

	@Override
	public void showCreateForm() {
		/* Action impossible. */
	}

	@Override
	public void showDeleteForm(long scheduleId, String scheduleName) {
		/* Action impossible. */
	}

	@Override
	public void showLessonList(long scheduleId) {
		/* Action impossible. */
	}

}// class LessonList